package com.wlc.thread.lockdemo;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 锁
 * @date 2021-10-31 16:04
 */
public class LockDemo01 {


    public static void main(String[] args) {
        method01();
    }
    public static int method02(){
        int result = 0;
        try {
            result = 1;
            int a = 2/0;
            return result;
        }catch (Exception e){
            result = 2;
            return result;
        }finally {
            result = 3;
            return result;
        }
    }

    public static void method01() {
        Lock lock = new ReentrantLock();
        lock.lock();
        try {
            System.out.println("获得锁");
            int a = 2/0;
            throw new Exception("这是一个异常");
        } catch (Exception e) {
        } finally {
            lock.unlock();
            System.out.println("释放锁");
        }

    }



}
